/**
 * 项目名称: Topic_993.cpp
 * 项目路径: study/DataStructure/LeetCode/树/简单
 * 编辑时间: 2024年08月13日15时28分35秒
 * 用   户: 轻尘
 */

#include <bits/stdc++.h>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    struct node{
        int val;
        int study;
        int parent;
    };
    vector<node>no;
    bool flag = false;
    void pre(TreeNode* root,int study){
        if(!root)return;
        else study++;
        if(root->left){
            node p;
            p.val = root->left->val;
            p.parent = root->val;
            p.study = study;
            no.push_back(p);
            pre(root->left,study);
        }

        if(root->right){
            node p;
            p.val = root->right->val;
            p.parent = root->val;
            p.study = study;
            no.push_back(p);
            pre(root->right,study);
        }
    }
    bool isCousins(TreeNode* root, int x, int y) {
        pre(root,0);
        node p1,p2;
        for(auto k:no){
            if(k.val == x)p1=k;
            if(k.val == y)p2=k;
        }

        if(p1.study == p2.study && p1.parent != p2.parent)flag = true;
        return flag;
    }
};

int main() {

    return 0;
}
